import request from '@/utils/request'

// 查询所有设备
export function getEquipList(page, pagesize, searchItem) {
  let urls = `/equipment/equip?page=${page}&pagesize=${pagesize}`
  for (const key in searchItem) {
    urls = urls + '&' + key + '=' + searchItem[key]
  }
  return request({
    url: urls,
    method: 'get'
  })
}
// 添加设备
export function addEquip(data) {
  // 返回一个axios对象 => promise  // 返回了一个promise对象
  return request({
    url: '/equipment/equip',
    method: 'post',
    data
  })
}
// 删除设备
export function delEquip(id) {
  return request({
    url: `/equipment/equip?id=${id}`,
    method: 'delete'
  })
}

// 删除设备
export function delLend(id) {
  return request({
    url: `/equipment/lend?id=${id}`,
    method: 'delete'
  })
}
// 修改设备
export function editEquip(data) {
  // 返回一个axios对象 => promise  // 返回了一个promise对象
  return request({
    url: '/equipment/equip',
    method: 'put',
    data
  })
}
// 获取设备详情设备
export function getEquipDetail(id) {
  return request({
    url: `/equipment/detail?id=${id}`,
    method: 'get'
  })
}

// 获取设备借用记录1
export function getEquipHistoryByProgress(page, pagesize, searchItem) {
  let urls = `/equipment/phistory?page=${page}&pagesize=${pagesize}`
  for (const key in searchItem) {
    urls = urls + '&' + key + '=' + searchItem[key]
  }
  return request({
    url: urls,
    method: 'get'
  })
}

// 获取设备借用记录2
export function getEquipHistoryByEquipid(equipid) {
  const url = `/equipment/ehistory?id=${equipid}`
  return request({
    url,
    method: 'get'
  })
}

// 获取设备借用记录3
export function getWaitAuditEquipHistory(page, pagesize, searchItem) {
  let urls = `/equipment/whistory?page=${page}&pagesize=${pagesize}`
  for (const key in searchItem) {
    urls = urls + '&' + key + '=' + searchItem[key]
  }
  return request({
    url: urls,
    method: 'get'
  })
}
// 借用设备
export function lendEquip(data) {
  return request({
    url: '/equipment/lend',
    method: 'post',
    data
  })
}

// 归还设备
export function returnEquip(id, equipid) {
  return request({
    url: `/equipment/return?id=${id}&equipid=${equipid}`,
    method: 'post'
  })
}

// 审核
export function auditEquipLend(id, equipid, progress) {
  return request({
    url: `/equipment/audit?id=${id}&equipid=${equipid}&progress=${progress}`,
    method: 'put'
  })
}
// 学生借用记录
export function lendHistoryByStudent(stundent) {
  return request({
    url: `/equipment/user?student=${stundent}`,
    method: 'get'
  })
}
// 根据id查询借用记录
export function lendHistoryById(id) {
  return request({
    url: `/equipment/lenddetail?id=${id}`,
    method: 'get'
  })
}
